import { ApiProperty } from '@nestjs/swagger';
import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Payment } from './payment.entity';
import { Room } from './room.entity';
import { User } from './user.entity';

@Entity()
export class Order {
  @ApiProperty({ description: '订单ID', example: 1 })
  @PrimaryGeneratedColumn()
  orderID: number;

  @ApiProperty({ description: '用户ID', example: 1 })
  @Column()
  userId: number;

  @ApiProperty({ description: '房间ID', example: 1 })
  @Column()
  roomID: number;

  @ApiProperty({
    description: '入住日期',
    example: '2023-09-10T00:00:00.000Z',
    type: Date,
  })
  @Column({ type: 'datetime' })
  checkInDate: Date;

  @ApiProperty({
    description: '离店日期',
    example: '2023-09-15T00:00:00.000Z',
    type: Date,
  })
  @Column({ type: 'datetime' })
  checkOutDate: Date;

  @ApiProperty({ description: '订单的用户信息', type: () => User })
  @ManyToOne(() => User, (user) => user.orders)
  @JoinColumn({ name: 'userId' })
  user: User;

  @ApiProperty({ description: '订单的房间信息', type: () => Room })
  @ManyToOne(() => Room, (room) => room.orders)
  @JoinColumn({ name: 'roomID' })
  room: Room;

  @ApiProperty({ description: '订单的支付记录', type: () => [Payment] })
  @OneToMany(() => Payment, (payment) => payment.order)
  payments: Payment[];
}
